﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NetFrame;
using NetFrame.Auto;

namespace LOLServer.Logic
{
    public abstract class AbsHandlerBase
    {
        private byte mType;
        private int mArea=0;

        public virtual byte GetGameType()
        {
            return mType; 
        }

        public void SetGameType(byte _type)
        { 
            mType = _type;
        }

        public virtual int GetArea()
        {
            return mArea;
        }

        public void SetArea(int _area)
        {
            mArea = _area;
        }
        public byte GetOrSetType { get; set; }
        public int GetOrArea { get; set; }
        #region  通过连接对象发送
        public void SendMsg(UserToken _ut, int _command)
        {
            SendMsg(_ut,_command,null);
        }
        public void SendMsg(UserToken _ut, int _command, object _msg)
        {
            SendMsg(_ut, GetArea(), _command,_msg);
        }
        public void SendMsg(UserToken _ut, int _area, int _command, object _msg)
        {
            SendMsg(_ut,GetGameType(), GetArea(), _command,_msg);
        }
        public void SendMsg(UserToken _ut, byte _type, int _command, object _msg)
        {
            SendMsg(_ut, _type, GetArea(), _command,_msg);
        }
        public void SendMsg(UserToken _ut, byte _type, int _area, int _command, object _msg)
        {
            byte[] value = MessageEncoding.Encode(CreateSocketModel(_type, _area, _command, _msg));
            value = LengthEncoding.encode(value);
            _ut.WriteData(value); 
        }
        #endregion

        #region  通过玩家ID发送
        public void SendMsg(int _id, int _command)
        {

        }
        public void SendMsg(int _id, int _command, object _msg)
        {

        }
        public void SendMsg(int _id, int _area, int _command, object _msg)
        {

        }
        public void SendMsg(int _id, byte _type, int _area, int _command, object _msg)
        {

        }
        #endregion

        public SocketModel CreateSocketModel(byte _type, int _area, int _command, object _msg)
        {
            return new SocketModel(_type, _area, _command, _msg);
        }
    }
}
